package com.wchen.project.service;

import com.wchen.project.ticket.service.ITicketAsyncService;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.Arrays;
import java.util.List;

/**
 * @Description :
 * @author: cww
 * @DateTime: 2019/2/2 15:29
 */
@Slf4j
@Component
public class TicketController {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());
    @Value("${app.date}")
    private String date_arr_config;
    private static String date_arr;
    private static List<String> dateList;
    @Autowired
    private ITicketAsyncService ticketServiceThread;

    @PostConstruct
    public void transport() {
        date_arr = this.date_arr_config;
        dateList = Arrays.asList(date_arr.split(","));
    }

    @Scheduled(cron = "0/10 * * * * ?")
    public void getTicket(){

        for (final String date : dateList) {
            logger.info("线程开启查询：" + date);
            ticketServiceThread.getTicketAndSendMailByDay(date);
            logger.info("线程查询结束");
        }
    }

//    @Scheduled(cron = "0 */1 * * * ?")
    public void getMyOrderNoComplete() throws Exception {

        logger.info("检查登录状态开始");
        ticketServiceThread.getloginconf();
        logger.info("检查登录状态结束");
        logger.info("查询个人中心开始");
        ticketServiceThread.getMyOrderNoComplete("https://kyfw.12306.cn/otn/index/initMy12306Api");
        logger.info("查询个人中心结束");
        logger.info("查询未完成订单开始");
        ticketServiceThread.getMyOrderNoComplete("https://kyfw.12306.cn/otn/queryOrder/queryMyOrderNoComplete");
        logger.info("查询未完成订单结束");
    }
}
